home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE01 / TIPTRIX / LISTING8.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-06-01  |  1.2 KB  |  58 lines

  1. type
  2.   cNCCanvas = class(TCanvas)
  3.   private
  4.     FDeviceContext: HDC;
  5.     FWindowHandle : HWnd;
  6.     function     GetWindowRect:TRect;
  7.   protected
  8.     procedure    CreateHandle; override;
  9.     procedure    FreeHandle;
  10.   public
  11.     constructor  Create(aWindow: hWnd);
  12.     destructor   Destroy; override;
  13.     property     WindowRect: TRect read GetWindowRect;
  14.   end;
  15.  
  16. constructor cNCCanvas.Create(aWindow: hWnd);
  17. begin
  18.   inherited Create;
  19.   FWindowHandle:=aWindow;
  20. end;
  21.  
  22. destructor  cNCCanvas.Destroy;
  23. begin
  24.   FreeHandle;
  25.   inherited Destroy;
  26. end;
  27.  
  28. procedure cNCCanvas.CreateHandle;
  29. begin
  30.   if FWindowHandle=0 then inherited CreateHandle else
  31.   begin
  32.     if FDeviceContext = 0 then
  33.        FDeviceContext := GetWindowDC(FWindowHandle);
  34.     Handle := FDeviceContext;
  35.   end;
  36. end;
  37.  
  38. procedure cNCCanvas.FreeHandle;
  39. begin
  40.   Handle := 0;
  41.   if FDeviceContext <> 0 then
  42.   begin
  43.     ReleaseDC(FWindowHandle, FDeviceContext);
  44.     FDeviceContext:=0;
  45.   end;
  46. end;
  47.  
  48. function cNCCanvas.GetWindowRect:TRect;
  49. begin
  50.   winProcs.GetWindowRect(FWindowHandle,Result);
  51.   With Result do
  52.   begin
  53.     Right:=Pred(Right-Left);
  54.     Bottom:=Pred(Bottom-Top);
  55.     Left:=0; Top:=0;
  56.   end;
  57. end;
  58.